/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entities;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Alex
 */
@Entity
@Table(name = "T04_NOTE")
@NamedQueries({
    @NamedQuery(name = "Note.findAll", query = "SELECT n FROM Note n"),
    @NamedQuery(name = "Note.findById", query = "SELECT n FROM Note n WHERE n.id = :id"),
    @NamedQuery(name = "Note.findByNoteText", query = "SELECT n FROM Note n WHERE n.noteText = :noteText"),
    @NamedQuery(name = "Note.findByCreatorId", query = "SELECT n FROM Note n WHERE n.creatorId = :creatorId"),
    @NamedQuery(name = "Note.findByColumnId", query = "SELECT n FROM Note n WHERE n.columnId = :columnId"),
    @NamedQuery(name = "Note.findByNoteType", query = "SELECT n FROM Note n WHERE n.noteType = :noteType"),
    @NamedQuery(name = "Note.findByPriority", query = "SELECT n FROM Note n WHERE n.priority = :priority"),
    @NamedQuery(name = "Note.findByAssignedTo", query = "SELECT n FROM Note n WHERE n.assignedTo = :assignedTo"),
    @NamedQuery(name = "Note.findByEstimation", query = "SELECT n FROM Note n WHERE n.estimation = :estimation"),
    @NamedQuery(name = "Note.findByStartDate", query = "SELECT n FROM Note n WHERE n.startDate = :startDate"),
    @NamedQuery(name = "Note.findByEndDate", query = "SELECT n FROM Note n WHERE n.endDate = :endDate"),
    @NamedQuery(name = "Note.findByProject", query = "SELECT n FROM Note n WHERE n.projColumn.projId.projId = :projId AND n.endDate IS NULL"  ),
    @NamedQuery(name = "Note.findByProjectWithHistory", query = "SELECT n FROM Note n WHERE n.projColumn.projId.projId = :projId"  )
})
public class Note implements Serializable, Cloneable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "ID")
    private Long id;
    @Basic(optional=false)
    @Column(name="NOTE_ID")
    private Long noteId;
    @Basic(optional = false)
    @Column(name = "NOTE_TEXT")
    private String noteText;
    @Basic(optional=false)
    @Column(name="NOTE_DES")
    private String noteDesc;
    @Basic(optional = false)
    @Column(name = "CREATOR_ID")
    private long creatorId;
    @Basic(optional = false)
    @Column(name = "COLUMN_ID")
    private long columnId;
    @Basic(optional = false)
    @Column(name = "NOTE_TYPE")
    private long noteType;
    @Column(name = "PRIORITY")
    private Long priority;
    @Column(name = "ASSIGNED_TO")
    private Long assignedTo;
    @Column(name = "ESTIMATION", precision=2)
    private BigDecimal estimation;
    @Column(name = "START_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date startDate;
    @Column(name = "END_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date endDate;

    @OneToOne
    @JoinColumn(name="COLUMN_ID", referencedColumnName="ID", insertable=false, updatable=false)
    private ProjColumn projColumn;


    public Note() {
    }

    public Note(Long id) {
        this.id = id;
    }

    public Note(Long id, String noteText, long creatorId, long columnId, long noteType) {
        this.id = id;
        this.noteText = noteText;
        this.creatorId = creatorId;
        this.columnId = columnId;
        this.noteType = noteType;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNoteText() {
        return noteText;
    }

    public void setNoteText(String noteText) {
        this.noteText = noteText;
    }

    public long getCreatorId() {
        return creatorId;
    }

    public void setCreatorId(long creatorId) {
        this.creatorId = creatorId;
    }

    public long getColumnId() {
        return columnId;
    }

    public void setColumnId(long columnId) {
        this.columnId = columnId;
    }

    public long getNoteType() {
        return noteType;
    }

    public void setNoteType(long noteType) {
        this.noteType = noteType;
    }

    public Long getPriority() {
        return priority;
    }

    public void setPriority(Long priority) {
        this.priority = priority;
    }

    public Long getAssignedTo() {
        return assignedTo;
    }

    public void setAssignedTo(Long assignedTo) {
        this.assignedTo = assignedTo;
    }

    public BigDecimal getEstimation() {
        if (estimation == null)
            return BigDecimal.valueOf(0.00);
        return estimation;
    }

    public void setEstimation(BigDecimal estimation) {
        this.estimation = estimation;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Note)) {
            return false;
        }
        Note other = (Note) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Note[id=" + id + "]";
    }

    @Override
    public Object clone() {
        Note noteClone = new Note();
        
        noteClone.setColumnId(this.getColumnId());
        noteClone.setAssignedTo(this.getAssignedTo());
        noteClone.setEstimation(this.getEstimation());
        noteClone.setEndDate(this.getEndDate());
        noteClone.setStartDate(this.getStartDate());
        noteClone.setNoteText(this.getNoteText());
        noteClone.setNoteType(this.getNoteType());
        noteClone.setPriority(this.getPriority());
        noteClone.setCreatorId(this.getCreatorId());
        noteClone.setNoteDesc(this.getNoteDesc());

        return noteClone;
    }

    /**
     * @return the projColumn
     */
    public ProjColumn getProjColumn() {
        return projColumn;
    }

    /**
     * @param projColumn the projColumn to set
     */
    public void setProjColumn(ProjColumn projColumn) {
        this.projColumn = projColumn;
    }

    /**
     * @return the noteId
     */
    public long getNoteId() {
        return noteId;
    }

    /**
     * @param noteId the noteId to set
     */
    public void setNoteId(long noteId) {
        this.noteId = noteId;
    }

    /**
     * @return the noteDesc
     */
    public String getNoteDesc() {
        return noteDesc;
    }

    /**
     * @param noteDesc the noteDesc to set
     */
    public void setNoteDesc(String noteDesc) {
        this.noteDesc = noteDesc;
    }

}
